<extend name="Public/base"/>
<block name="content">


        <div id="pass" class="layui-form-item" style="display:block; ">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" lay-verify="pass" placeholder="请输入密码" autocomplete="off"
                       class="layui-input">
                <div class="layui-input-block" hidden>
                    <input type="tel" name="admin_id" value="<?php $user = session('user');echo $user[0]['id'];?>">
                </div>
                <div id="pwdmsg"></div>
                <button class="layui-btn" style="margin-top: 10px;" lay-submit lay-filter="*" >确定</button>
            </div>
        </div>
    <form class="layui-form layui-form-pane1" action="" method="post" style=" display :none;">
        <div class="layui-form-item">
            <div class="layui-inline">
                <div id="hint"></div>
                <label class="layui-form-label">密保问题</label>
                <div class="layui-input-block">
                    <select name="quiz">
                        <option value="">请选择问题</option>
                        <option value="你工作的第一个城市">你工作的第一个城市</option>
                        <option value="你的工号">你的工号</option>
                        <option value="你最喜欢的老师">你最喜欢的老师</option>
                    </select>
                </div>
                <div style="margin-top: 10px;">
                    <label class="layui-form-label">答案</label>
                    <div class="layui-input-block">
                        <input type="text" name="quiz_answer" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-input-block" hidden>
            <input type="tel" name="admin_id" value="<?php $user = session('user');echo $user[0]['id'];?>">
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <block name="js">
        <script src="__PUBLIC__/layui/layui.all.js"></script>
        <script>
            layui.use('form', function () {
                var data = {};
                var $ = layui.jquery;
                $('input[name="password"]').click(function(){
                    data.admin_id = $('input[name="admin_id"]').val();
                    $.post("{:U('Admin/checkEncrypted')}",data,function (e) {
                        if(e.code==1){
                            $('.layui-btn').removeAttr("disabled");
                        }else{
                            $('#hint').html('<font color="red">是不是傻！你已经设置过了密保信息啦！</font>')
                        }
                    })
                })
                $('.layui-btn').click(function () {
                    data.password = $('input[name="password"]').val();
                    $.post("{:U('Admin/checkPwd')}", data, function (e) {
                        if (e.code == 1){
                            $('#pwdmsg').html('<font color="red">密码不正确哦！请重新输入密码！</font>')
                        }else{
                            $('#pass').css("display","none");
                            $('form').css("display", "block");
                        }
                    })
                })
                $('form').submit(function(){
                    data.quiz = $('select').val();
                    data.quiz_answer = $('input[name="quiz_answer"]').val();
                    data.admin_id = $('input[name="admin_id"]').val();
                    console.log(data);
                    $.post("{:U('Admin/secure')}",data,function (e) {
                      if(e.code==1){
                      }
                          alert('密保设置成功！');
                        window.location.reload();
                    })
                    return false;
                })

            })
        </script>
    </block>


</block>